import os
import requests
from pathlib import Path

def ensure_dir(directory):
    Path(directory).mkdir(parents=True, exist_ok=True)

def download_file(url, path):
    response = requests.get(url)
    if response.status_code == 200:
        with open(path, 'wb') as f:
            f.write(response.content)
        print(f"Downloaded: {path}")
    else:
        print(f"Failed to download: {url}")

def main():
    # 创建目录
    directories = [
        'app/static/images',
        'app/static/fonts/fontawesome',
        'app/static/uploads/husbands',
        'app/static/uploads/wives'
    ]
    for directory in directories:
        ensure_dir(directory)

    # Font Awesome 文件
    fontawesome_files = {
        'fa-solid-900.woff2': 'https://use.fontawesome.com/releases/v5.15.4/webfonts/fa-solid-900.woff2',
        'fa-solid-900.woff': 'https://use.fontawesome.com/releases/v5.15.4/webfonts/fa-solid-900.woff',
        'fa-solid-900.ttf': 'https://use.fontawesome.com/releases/v5.15.4/webfonts/fa-solid-900.ttf',
        'fa-solid-900.eot': 'https://use.fontawesome.com/releases/v5.15.4/webfonts/fa-solid-900.eot'
    }

    for filename, url in fontawesome_files.items():
        path = f'app/static/fonts/fontawesome/{filename}'
        download_file(url, path)

    # AOS 文件
    aos_files = {
        'aos.js': 'https://unpkg.com/aos@2.3.1/dist/aos.js',
        'aos.css': 'https://unpkg.com/aos@2.3.1/dist/aos.css'
    }

    for filename, url in aos_files.items():
        if filename.endswith('.js'):
            path = f'app/static/js/{filename}'
        else:
            path = f'app/static/css/{filename}'
        download_file(url, path)

if __name__ == '__main__':
    main() 